<template>
  <div id="menu_app">
    <div class="control_button">
      <el-button type="primary" round plain @click="isShow.flag = true"
        >新增</el-button
      >
    </div>

    <el-table
      :data="menuList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="title" label="标题菜单"> </el-table-column>
      <el-table-column prop="icon" label="菜单图标">
        <template v-slot="$props">
          <i :class="$props.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column prop="status" label="菜单状态">
        <template v-slot="$props">
          <el-button
            type="danger"
            round
            plain
            size="mini"
            v-if="$props.row.status == 1"
            >正常</el-button
          >
          <el-button type="warning" round plain size="mini" v-else
            >禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column prop="name" label="操作">
        <template v-slot="$props">
          <el-button
            type="warning"
            round
            plain
            size="mini"
            @click="edior_menu($props.row)"
            >编辑</el-button
          >
          <el-button type="danger" round plain size="mini" @click="del_menu($props.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Dialog :isShow="isShow" :menuList="menuList" ref="dialog_ref" />
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
import Dialog from "./addMenu.vue";

export default {
  components: {
    Dialog,
  },
  data() {
    return {
      isShow: { flag: false },
    };
  },
  computed: {
    ...mapState("menu_model", ["menuList"]),
  },
  methods: {
    edior_menu(obj) {
      //打开面板
      this.isShow.flag = true;
      //将数据设置进去
      this.$refs.dialog_ref.setData(obj);
    },
    del_menu(id){
      this.$axios.post("/menudelete",{id}).then(
        res=>{
          if(res.code==200){
            this.$message({
              type:"success",
              message:"删除成功"
            })
            this.menuListActions()
          }
        }
      )
    },
    ...mapActions("menu_model", ["menuListActions"]),
  },
  created() {
    this.menuListActions();
  },
};
</script>

<style>

</style>